//显示隐藏
$(".BannerStatus").click(function () {
    var id = $(this).data('value');
    var status = $(this).data('index');
    $.ajax({
        url:"/banner/editStatus",
        data:{
            id : id,
            status:status
        },
        type:"post",
        success:function (data) {
            if (data.code == 0){
                layer.msg("操作成功");
                location.reload();
            }else{
                layer.msg("操作失败");
            }
        }
    })
});
//打开添加弹出层
$(".addBanner").click(function () {
    layer.open({
        type:2,
        title:"新增",
        content:["/banner/editBanner",'yes'],
        area:["600px","500px"]
    });
});
//打开编辑弹出层
$(".BannerEdit").click(function () {
    var id = $(this).data('value');
    var url = "/banner/editBanner?id="+ id;
    layer.open({
        type:2,
        title:"编辑",
        content:[url,'yes'],
        area:["600px","500px"]
    });
});

//前台
$(".lookBanner").click(function () {
    window.open("/index","首页");
});
//删除banner
$(".delBanner").click(function () {
    var id = $(this).data('value');
    $.ajax({
        url:"/banner/delBanner",
        data:{
            id : id
        },
        type:"post",
        success:function (data) {
            if (data.code == 0){
                setTimeout(layer.msg("删除成功"),1000);
                location.reload()
            }else{
                layer.msg("操作失败");
            }
        }
    })
});

//保存banner
$(".bannerSubmit").click(function () {
    $.ajax({
        url:"/banner/saveAndEdit",
        data:$("#bannerForm").serialize(),
        success:function (data) {
            if(data.code == 0){
                layer.msg("操作成功！");
                cancel();
            }else{
                layer.msg("操作失败！");
            }
        }
    });
});

//关闭弹出层
$(".bannerClose").click(function () {
    cancel();
})

//关闭弹出层刷新list页面
function cancel(){
    window.parent.location.reload();
    window.parent.layer.closeAll();
}